473,441 Members | 1,459 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

Display Menu

Hi All

I'm a total newbie to Java.

I'm creating a very simple banking system as a college project. I'm doing ok... logging in the user, the displaying a Main Menu with options to select from. However Im using a If statement for the selection and once I have selected an option (for example = check account balance) I cant go back to the Main Menu (unless I write the whole thing out again, which would be daft).

I have tried to write a method (?) to display the menu, I can then put this at the end of my if statement to return the user to the Main Menu. However I can get it to work... Below is my menu code and below that the code i attempted for the method, if I can resolve this then im pretty much flying at the minute its the only thing holding me back!!!

Expand|Select|Wrap|Line Numbers
  1. //Show menu and get users choice
  2.         accChoice = JOptionPane.showInputDialog(null, "Account Menu \n" +
  3.                                           "What would you like to do? \n" +
  4.                                           " 1 - Check Balance.\n" +
  5.                                           " 2 - Make A Withdrawl.\n" +
  6.                                           " 3 - Make A Deposit.\n"+
  7.                                           " 4 - Amend Overdraft.\n" +
  8.                                           " 5 - Exit.\n" +
  9.                                           "Please enter your choice:");
  10.  
  11.     //direct users choice
  12.         if (accChoice.equals(accChoice1))
  13.         {
  14.             System.out.println("1 - Check Balance.");
  15.         }
  16.         else if (accChoice.equals(accChoice2))
  17.         {
  18.             System.out.println("2 - Make A Withdrawl");
  19.         }
  20.         else if (accChoice.equals(accChoice3))
  21.         {
  22.             System.out.println("3 - Make A Deposit.");
  23.         }
  24.         else if (accChoice.equals(accChoice4))
  25.         {
  26.             System.out.println("4 - Amend Overdraft.");
  27.         }
  28.         else if (accChoice.equals(accChoice5))
  29.         {
  30.             System.out.println("5 - Exit");
  31.         }
below is my method(s) code:

Expand|Select|Wrap|Line Numbers
  1. private String displayMainMenu()
  2.     {
  3.         String accChoice;
  4.         accChoice = JOptionPane.showInputDialog(null, "Account Menu \n" +
  5.                                           "What would you like to do? \n" +
  6.                                           " 1 - Check Balance.\n" +
  7.                                           " 2 - Make A Withdrawl.\n" +
  8.                                           " 3 - Make A Deposit.\n"+
  9.                                           " 4 - Amend Overdraft.\n" +
  10.                                           " 5 - Exit.\n" +
  11.                                           "Please enter your choice:");
  12.         return accChoice;
  13.  
  14.    }
May 22 '09 #1
2 9399
JosAH
11,448 Expert 8TB
If you can wait one more day or so then I'll post a little article about this topic because I've seen people struggle with this item more than often. The solution (which you can reuse over and over again!) will be a bit of code that represents a single menu item as well as an entire menu. You can nest menus at will and put in "back" and "quit" menu items whereever you want.

kind regards,

Jos

edit: done; read the 'insights' section of the Java forum: it contains a little article about this very topic.
May 30 '09 #2
Hi Josah,

Can I check where I can find the article on the display menu in java? Thanks!!
Jul 28 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Al Sav | last post by:
Hi, I am trying to create a menu for asp.net page. The menu-detail list display, when mouse hovers over the main menu list, like you see in regular windows apps. When the detail-menu-list window...
6
by: Jamie | last post by:
Hi all, I have a page in which I display a menu which is a table within a div element. Each cell in the table is a menu item with an "onclick" event handler assigned. I want to make it so...
7
by: Marc | last post by:
Hi everyone. I am having trouble with a stylesheet in mozilla. It is part of turning a list into a menu: #menu li{ margin: 0; display: inline; vertical-align: bottom;
12
by: mdb | last post by:
My app has a notify icon in the systray. I want the left mouse click to initiate a menu, and a right-mouse click to do something else. Normally, for a button, I would listen to MouseDown and if I...
4
by: txican | last post by:
the HTML is: ---------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html> <head> <title>foo</title>...
3
by: hzgt9b | last post by:
Using VS2005, VB.NET, I am developing a windows app that has a DataGridView. I want to enable the display of a context menu on this DataGridView only when a specific set of keys is also pressed...
0
by: rehanmomin | last post by:
Just to start off, I am writing a web application using C#. I have a Menu which is binded to an XML datasource. There are three menu items each with submenus and a textbox where I want to display...
2
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
2
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.